import 'package:ichinesereader/models/book/BookFolders.dart';
import 'package:ichinesereader/utils/regex.dart';
import 'package:reactive_file_picker/reactive_file_picker.dart';
import 'package:reactive_forms/reactive_forms.dart';
import '../../pages/schooladmin/adminTeacherEditor.dart';

class LoginFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'remember': FormControl<bool>(value: false),
    'password': FormControl<String>(
        validators: [Validators.required, Validators.minLength(6)]),
  });
}

class LevelPercentageFormModel {
  final form = FormGroup({
    'levelDisplayName': FormControl<String>(validators: [Validators.required]),
    'levelPercentage': FormControl<int>(value: 0)
  });
}

class LevelRainbowSegmentedFormModel {
  final form = FormGroup({
    'icrLevel': FormControl<String>(validators: [Validators.required]),
    'actflLevel': FormControl<String>(value: ''),
  });
}

//https://ichinesereader.com/icr/teacher/class/student#student
class StudentDetailsEditFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'email': FormControl<String>(),
    'security': FormControl<String>(),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'nickname': FormControl<String>(validators: [Validators.maxLength(150)]),
    'dateofbirth': FormControl<DateTime>(),
    'gender': FormControl<String>(value: 'female'),
    'level': FormControl<String>(value: 'level1'),
    'progresslevel': FormControl<String>(),
    'audiotype': FormControl<String>(),
    'texttype': FormControl<String>(),
    'pinyinenabled': FormControl<bool>(value: true),
    'parentemail': FormControl<String>(),
    // 'password': FormControl<String>(validators: [Validators.required]),
  });
}

class StudentDetailsNewFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'email': FormControl<String>(),
    'nickname': FormControl<String>(),
    'dateofbirth': FormControl<DateTime>(),
    'gender': FormControl<String>(),
    'level': FormControl<String>(value: 'level1'),
    'password': FormControl<String>(
        validators: [Validators.required, Validators.minLength(6)]),
    'progresslevel': FormControl<String>(),
    'audiotype': FormControl<String>(),
    'texttype': FormControl<String>(),
    'pinyinenabled': FormControl<bool>(value: true),
    'parentemail': FormControl<String>(),
  });
}

class ResetPasswordFormModel {
  final form = FormGroup({
    'password': FormControl<String>(
        validators: [Validators.required, Validators.minLength(6)]),
    'confirmpassword': FormControl<String>()
  }, validators: [
    Validators.mustMatch('password', 'confirmpassword')
  ]);
}

class ChangePasswordFormTeacherModel {
  final form = FormGroup(
    {
      'currentpassword': FormControl<String>(validators: [Validators.required]),
      'newpassword': FormControl<String>(
          validators: [Validators.pattern(Patterns.passwordHard)])
    },
  );
}

class ChangePasswordWithConfirmFormModel {
  final form = FormGroup(
    {
      'currentpassword': FormControl<String>(validators: [Validators.required]),
      'newpassword': FormControl<String>(
          validators: [Validators.required, Validators.minLength(6)]),
      'passwordConfirmation': FormControl<String>()
    },
    validators: [Validators.mustMatch('newpassword', 'passwordConfirmation')],
  );
}

class StrongPasswordFormTeacherModel {
  final form = FormGroup({
    'currentpassword': FormControl<String>(validators: [Validators.required]),
    'newpassword': FormControl<String>(
        validators: [Validators.pattern(Patterns.passwordHard)]),
    'confirmpassword': FormControl<String>(),
  }, validators: [
    Validators.mustMatch('newpassword', 'confirmpassword'),
  ]);
}

class ChangePasswordFormModel {
  final form = FormGroup(
    {
      'currentpassword': FormControl<String>(validators: [Validators.required]),
      'newpassword': FormControl<String>(validators: [Validators.minLength(6)]),
    },
  );
}

class IndividualDetailsEditFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'email': FormControl<String>(),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'nickname': FormControl<String>(),
    'dateofbirth': FormControl<DateTime>(),
    'gender': FormControl<String>(),
    'progresslevel': FormControl<String>(),
    'bookaudio': FormControl<String>(),
    'texttype': FormControl<String>(),
    'pinyinenabled': FormControl<bool>(value: true),
    'parentemail': FormControl<String>(),
  });
}

//https://ichinesereader.com/icr/teacher/class/student#announcement
class AnnouncementFormModel {
  final form = FormGroup({
    'students': FormControl<List<String>>(),
    'allstudents': FormControl<bool>(value: true),
    'message': FormControl<String>(validators: [Validators.required]),
    'points': FormControl<int>(value: 0)
  });
}

class CreateOrAddtoFolderFormModel {
  final form = FormGroup({
    'folders': FormControl<AllFolder>(),
    'newfolder': FormControl<bool>(value: false),
    'newfoldername': FormControl<String>(value: ''),
  });
}

//https://ichinesereader.com/icr/teacher//myWords
class WordFormModel {
  final form = FormGroup({
    'word': FormControl<String>(validators: [Validators.required]),
    'pinyin': FormControl<String>(validators: [Validators.required]),
    'pronunciation': FormControl<String>(validators: [Validators.required]),
    'pos': FormControl<String>(validators: [Validators.required]),
    'explain': FormControl<String>(),
    'example': FormControl<String>(),
    'picture': FormControl<String>(validators: [Validators.required])
  });
}

//https://ichinesereader.com/icr/teacher/class/student#classSettings
class ClassSettingsFormModel {
  final form = FormGroup({
    'program': FormControl<String>(),
    'subprogram': FormControl<String>(validators: [Validators.required]),
    'students': FormControl<List<String>>(),
    'texttype': FormControl<String>(validators: [Validators.required]),
    'audiotype': FormControl<String>(validators: [Validators.required]),
    'viewreport': FormControl<bool>(value: true),
    'pinyinenabled': FormControl<bool>(value: true),
    'quizaudioenabled': FormControl<bool>(value: true),
    'evaluation': FormControl<bool>(value: true),
    'vocabulary': FormControl<bool>(value: true),
    'placementTest': FormControl<bool>(value: true),
    'interfaceChinese': FormControl<bool>(value: false),
    'quizThreshold': FormControl<bool>(value: true),
  });

  final formAdmin = FormGroup({
    'classId': FormControl<String>(),
    'className': FormControl<String>(validators: [Validators.required]),
    'program': FormControl<String>(),
    'subprogram': FormControl<String>(),
    'teachers': FormControl<List<String>>(),
    'texttype': FormControl<String>(validators: [Validators.required]),
    'audiotype': FormControl<String>(validators: [Validators.required]),
    'pinyinenabled': FormControl<bool>(value: true),
    'evaluation': FormControl<bool>(value: true),
    'vocabulary': FormControl<bool>(value: true),
    'placementTest': FormControl<bool>(value: true),
  });
}

class SchoolAdminProfileFormModel {
  final form = fb.group({
    'school': fb.group({
      'name': ['', Validators.required],
      'type': ['PUBLIC', Validators.required],
      'district': [''],
      'programs':
          FormControl<List<DropdownModel>>(validators: [Validators.required]),
      'timezone': [''],
    }),
    'contact': fb.group({
      'phone': FormControl<String>(),
      'email': ['', Validators.required, Validators.email],
    }),
    'address': fb.group({
      'street': FormControl<String>(),
      'city': FormControl<String>(),
      'zipcode': FormControl<String>(),
      'country': [''],
      'state': [''],
    }),
    'leaderboard': fb.group({
      // 'disableclass': [false],
      // 'disableworld': [false],
      // 'disableDirectLogin': [false],
      'disableclass': FormControl<bool>(value: true),
      'disableworld': FormControl<bool>(value: true),
      'disableDirectLogin': FormControl<bool>(value: true),
    }),
  });
}

////https://ichinesereader.com/icr/admin/school/accounts/class
///新创建的和修改的差一个 class id
///Class Name doesn't allow special characters(@$#...)
class ClassDetailsFormModel {
  final form = FormGroup({
    'classname': FormControl<String>(validators: [Validators.required]),
    'teachers': FormControl<List<String>>(),
    'texttype': FormControl<String>(validators: [Validators.required]),
    'audiotype': FormControl<String>(validators: [Validators.required]),
    'pinyinenabled': FormControl<bool>(value: true),
  });
}

class TeacherDetailsNewFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'classIds': FormControl<List<DropdownModel>>(),
    'email': FormControl<String>(validators: [Validators.required]),
    'password': FormControl<String>(
        validators: [Validators.required, Validators.minLength(6)]),
  });
}

class TeacherDetailsEditFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'classIds': FormControl<List<DropdownModel>>(),
  });
}

class ChangeEmailFormModel {
  final form = FormGroup({
    'email': FormControl<String>(
        validators: [Validators.required, Validators.email]),
    'confirmemail': FormControl<String>(
        validators: [Validators.required, Validators.email]),
  }, validators: [
    Validators.mustMatch('email', 'confirmemail'),
  ]);
}

class HomeworkFormModel {
  final form = fb.group({
    'settings': fb.group({
      'name': ['', Validators.required],
      'instruction': FormControl<String>(),
      'allstudents': FormControl<bool>(value: true),
      'students': FormControl<List<String>>(),
      'points': FormControl<int>(value: 0, validators: [Validators.max(5000)]),
      'startdate': FormControl<DateTime>(value: DateTime.now()),
      'duedate':
          FormControl<DateTime>(value: DateTime.now().add(Duration(days: 3))),
    }),
    'features': fb.group({
      'texttype': FormControl<String>(
          value: 'Simplified', validators: [Validators.required]),
      'audiotype': FormControl<String>(
          value: 'Mandarin', validators: [Validators.required]),
      'pinyinenabled': FormControl<bool>(value: true),
      'quizaudioenabled': FormControl<bool>(value: true),
    }),
    'review': fb.group({
      'totalbooks':
          FormControl<int>(value: 0, validators: [Validators.required]),
      'completerequired':
          FormControl<int>(value: 0, validators: [Validators.required]),
    }),
  });
}

class YearAndMonthFormModel {
  final form = fb.group(
      {'years': FormControl<List<String>>(), 'month': FormControl<String>()});
}

class FromAndToModel {
  final form = fb
      .group({'from': FormControl<DateTime>(), 'to': FormControl<DateTime>()});
}

class ActivityRequestModel {
  final form = fb.group({
    'past': FormControl<int>(),
    'activity': FormControl<List<String>>(),
    'entry': FormControl<List<String>>()
  });
}

class StudentDetailsParentEditFormModel {
  final form = FormGroup({
    'email': FormControl<String>(),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'dateofbirth': FormControl<DateTime>(),
    'gender': FormControl<String>(value: 'female'),
  });
}

class UserInfoFormModel {
  final form = FormGroup({
    'username': FormControl<String>(validators: [Validators.required]),
    'firstname': FormControl<String>(validators: [Validators.required]),
    'lastname': FormControl<String>(validators: [Validators.required]),
    'password': FormControl<String>(
        validators: [Validators.required, Validators.minLength(6)]),
    'confirmpassword': FormControl<String>(validators: [Validators.required]),
    'email': FormControl<String>(
        validators: [Validators.required, Validators.email]),
    'confirmemail': FormControl<String>(
        validators: [Validators.required, Validators.email]),
    'phoneNumber': FormControl<String>(validators: [Validators.required]),
    'subscription': FormControl<String>(validators: [Validators.required]),
  }, validators: [
    Validators.mustMatch('email', 'confirmemail'),
    Validators.mustMatch('password', 'confirmpassword'),
  ]);
}

class UserInfoExtraFormModel {
  final form = FormGroup({
    'dateOfBirth': FormControl<String>(),
    'gender': FormControl<String>(),
    'state': FormControl<String>(),
    'city': FormControl<String>(),
    'street': FormControl<String>(),
    'country': FormControl<String>(validators: [Validators.required]),
    'language': FormControl<String>(
        value: 'Simplified', validators: [Validators.required]),
    'lang': FormControl<String>(
        value: 'Mandarin', validators: [Validators.required]),
    'pinyin': FormControl<bool>(value: true),
  });
}

class SchoolRegisterFormStep1 {
  final form = FormGroup({
    'studentNumber': FormControl<int>(value: 0, validators: [
      Validators.min(1),
      Validators.max(5000),
      Validators.required
    ]),
    'paymentTerm': FormControl<int>(value: 1, validators: [
      Validators.min(1),
      Validators.max(3),
      Validators.required
    ]),
    'zipCode': FormControl<String>(
        value: '', validators: [Validators.required, Validators.minLength(5)]),
  });
}

class SchoolRegisterFormStep2 {
  final form = FormGroup({
    'schoolName':
        FormControl<String>(value: '', validators: [Validators.required]),
    'firstName':
        FormControl<String>(value: '', validators: [Validators.required]),
    'lastName':
        FormControl<String>(value: '', validators: [Validators.required]),
    'email': FormControl<String>(
        value: '', validators: [Validators.required, Validators.email]),
    'confirmemail':
        FormControl<String>(value: '', validators: [Validators.required]),
    'phone': FormControl<String>(value: ''),
  }, validators: [
    Validators.mustMatch('email', 'confirmemail')
  ]);
}

class PurchaseForm {
  final form = FormGroup({
    'paymentText':
        FormControl<String>(value: '', validators: [Validators.required]),
    'paymentFile': FormControl<MultiFile<String>>(
        value: const MultiFile<String>(
          files: [],
          platformFiles: [],
        ),
        validators: [Validators.required]),
  });
}
